SetWorkingDir A_ScriptDir

; ------------------------------- 键盘映射 -------------------------------
;#HotIf not WinActive("ahk_exe ToDesk.exe") and not WinActive("ahk_class OrayUI")
$Capslock::Esc
$ScrollLock::Capslock
SC163::LCtrl  ;  Fn 映射到 Left Ctrl
#HotIf

; -------------------------------- 快捷启动 ----------------------------------------
^!T::Run "wt"         ; 启动 windows terminal
^!Y::Run "E://ProgramFiles//msys64//mingw64.exe"         ; 启动 mingw64
^!c::Run "calc.exe"   ; 启动 计算器

;; Ctrl + Alt + Space 启动 google 搜索
^!space::run "https://www.google.com"


;; Ctrl+Alt+R 重新加载
^!r::
{
    ToolTip "Reload"
    SetTimer () => ToolTip(), -1000
    Sleep 1000
    reload
}

;; Alt + Pause 暂停/启动
!Pause::Pause ; 按一次 Alt-Pause 会暂停脚本. 再按一次则取消暂停.

; ------------------------------- 窗口管理  -------------------------------
; 移动窗口
>^Left::    MoveActiveWindowBy(-20,   0)
>^Right::   MoveActiveWindowBy(+20,   0)
>^Up::      MoveActiveWindowBy(  0, -20)
>^Down::    MoveActiveWindowBy(  0, +20)

MoveActiveWindowBy(x, y) {
    WinExist "A"  ; 使活动窗口成为 "上次找到的窗口"
    WinGetPos &current_x, &current_y
    WinMove current_x + x, current_y + y
}

; 最大化, 最小化, 关闭窗口
>^PgUp::    WinMaximize "A"
>^PgDn::    WinRestore "A"
>^End::     WinClose "A"

; 置顶
!Enter::
{
    WinSetAlwaysOnTop -1, "A"
    ExStyle := WinGetExStyle("A")
    if (ExStyle & 0x8)
    {
        ToolTip "OnTop On", 0, 0  ; 活动窗口左上角
        SetTimer () => ToolTip(), -1000
    }
    else
        ToolTip "OnTop Off", 0, 0  ; 活动窗口左上角
        SetTimer () => ToolTip(), -1000
}

; ------------------------------- 其他功能  -------------------------------
#HotIf WinActive("ahk_exe explorer.exe") ; 仅在资源管理器中生效
$#C::  ; Ctrl C 复制文件路径
{
    Send "^c"
    Sleep 500
    ToolTip A_Clipboard, 0, 0
    SetTimer () => ToolTip(), -1000
    A_Clipboard := A_Clipboard
}

#HotIf MouseIsOver("ahk_class Shell_TrayWnd") ; 在任务栏滚动鼠标调节音量
WheelUp::Send "{Volume_Up}"
WheelDown::Send "{Volume_Down}"

MouseIsOver(WinTitle) {
    MouseGetPos ,, &Win
    return WinExist(WinTitle " ahk_id " Win)
}